﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxGetAddress : AdminPage
    {
        public int id = 0;
        public string Province = "0", City = "0", Area = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 97)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                GetAddressInfo();
            }
        }
        private string ProvinceList
        {
            get
            {
                string html = "";
                IList<Model.CNVP_Province> model = new BLL.CNVP_Province().GetAll_CNVP_Province();
                html += "<select name=\"ListProvince\" id=\"ListProvince\" onchange=\"ProvinceChange();DeliveryFreight();\" >";
                html += "<option value=\"\">--请选择--</option>";
                foreach (Model.CNVP_Province p in model)
                {
                    string selectCB = "";
                    if (id > 0)
                    {
                        string Province_Str = "";
                        var model_GetAddress=new BLL.CNVP_GetAddress().GetSingle_CNVP_GetAddressById(id);
                        if (model_GetAddress != null)
                        {
                            Province_Str = model_GetAddress.Province;
                        }
                        if (p.Code == Province_Str)
                        {
                            selectCB = "selected='selected'";
                        }
                    }
                    html += "<option value=\"" + p.Code + "\" " + selectCB + ">" + p.Name + "</option>";
                }
                html += "</select>";
                return html;
            }
        }
        private void GetAddressInfo()
        {
            string html = "";
            if (id > 0)
            {
                Model.CNVP_GetAddress model = new Model.CNVP_GetAddress();
                model = new BLL.CNVP_GetAddress().GetSingle_CNVP_GetAddressById(id);
                if (model != null)
                {
                    Province = model.Province;
                    City = model.City;
                    Area = model.Area;
                    html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  width=\"100%\" class=\"division\">";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                收货地区：</th>";
                    html += "            <td colspan=\"2\">";
                    html += "                " + ProvinceList + "";
                    html += "                <span id=\"selectCity\"></span>";
                    html += "                <span id=\"selectArea\"></span>";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                收货地址：</th>";
                    html += "            <td colspan=\"2\" >";
                    html += "				<input id=\"txtGetAddress\" type=\"text\" name=\"txtGetAddress\" value=" + model.GetAddress + " >";
                    html += "				</td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                收货人姓名：</th>";
                    html += "            <td colspan=\"2\">";
                    html += "				<input id=\"txtTrueName\" type=\"text\" name=\"txtTrueName\" value=" + model.TrueName + " >";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                手机号码： ";
                    html += "            </th>";
                    html += "            <td colspan=\"2\">";
                    html += "				<input id=\"txtMobilePhone\" type=\"text\" name=\"txtMobilePhone\" value=" + model.MobilePhone + " >";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                固定电话： ";
                    html += "            </th>";
                    html += "            <td colspan=\"2\">";
                    html += "				<input id=\"txtPhone\" type=\"text\" name=\"txtPhone\" value=" + model.Phone + " >";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;编： ";
                    html += "            </th>";
                    html += "            <td colspan=\"2\">";
                    html += "				<input id=\"txtZipCode\" type=\"text\" name=\"txtZipCode\" value=" + model.ZipCode + " >";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "        <tr >";
                    html += "            <th >";
                    html += "                保存地址：</th>";
                    html += "            <td  colspan=\"2\">";
                    html += "				<input id=\"cbIsSave\" type=\"checkbox\" name=\"cbIsSave\" />";
                    html += "            </td>";
                    html += "        </tr>";
                    html += "</table>";
                }
            }
            else
            {
                html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  width=\"100%\" class=\"division\">";
                html += "        <tr >";
                html += "            <th >";
                html += "                收货地区：</th>";
                html += "            <td colspan=\"2\">";
                html += "                " + ProvinceList + "";
                html += "                <span id=\"selectCity\"></span>";
                html += "                <span id=\"selectArea\"></span>";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                收货地址：</th>";
                html += "            <td colspan=\"2\" >";
                html += "				<input id=\"txtGetAddress\" type=\"text\" name=\"txtGetAddress\" >";
                html += "				</td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                收货人姓名：</th>";
                html += "            <td colspan=\"2\">";
                html += "				<input id=\"txtTrueName\" type=\"text\" name=\"txtTrueName\" >";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                手机号码： ";
                html += "            </th>";
                html += "            <td colspan=\"2\">";
                html += "				<input id=\"txtMobilePhone\" type=\"text\" name=\"txtMobilePhone\"  >";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                固定电话： ";
                html += "            </th>";
                html += "            <td colspan=\"2\">";
                html += "				<input id=\"txtPhone\" type=\"text\" name=\"txtPhone\"  >";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;编： ";
                html += "            </th>";
                html += "            <td colspan=\"2\">";
                html += "				<input id=\"txtZipCode\" type=\"text\" name=\"txtZipCode\"  >";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr >";
                html += "            <th >";
                html += "                保存地址：</th>";
                html += "            <td  colspan=\"2\">";
                html += "				<input id=\"cbIsSave\" type=\"checkbox\" name=\"cbIsSave\" />";
                html += "            </td>";
                html += "        </tr>";
                html += "</table>";
            }
            html += "<script type=\"text/javascript\">";
            html += "	function ProvinceChange() { ";
            html += "	   var ddlProvince = document.getElementById(\"ListProvince\");";
            html += "		var selectCity = document.getElementById(\"selectCity\");";
            html += "		selectCity.innerHTML = GetAjaxResponse(\"../admin/CommonWindows/AjaxCity.aspx?Type=ProvinceID&Code=\" + ddlProvince.value);";
            html += "       if(" + id + " > 0)";
            html += "            { ";
            html += "                if(ddlProvince.value==" + Province + ")";
            html += "                {";
            html += "                    var ListCity = document.getElementById(\"ListCity\");";
            html += "                    ListCity.value=" + City + "";
            html += "                }";
            html += "            }";
            html += "		CityChange();";
            html += "	}";
            html += "	function CityChange() {";
            html += "		var ListCity = document.getElementById(\"ListCity\");";
            html += "		var selectArea = document.getElementById(\"selectArea\");";
            html += "		selectArea.innerHTML = GetAjaxResponse(\"../admin/CommonWindows/AjaxCity.aspx?Type=CityID&Code=\" + ListCity.value);";
            html += "           if(" + id + " > 0)";
            html += "           {";
            html += "	            if(ListCity.value==" + City + ")";
            html += "	            {";
            html += "		            var ListArea = document.getElementById(\"ListArea\");";
            html += "		            ListArea.value=" + Area + ";";
            html += "	            }";
            html += "           }";
            html += "	}";
            html += "</script>";
            Response.Write(html);
        }
    }
}